package com.cskaoyan.service;

import com.cskaoyan.bean.MarketSystem;
import com.cskaoyan.bean.MarketSystemExample;
import com.cskaoyan.mapper.MarketSystemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;


/**
 * @author : qj
 * @since: 2022/10/11  23:21
 */
@Service
public class AdminConfigServiceImpl implements AdminConfigService {
    @Autowired
    MarketSystemMapper marketSystemMapper;

    /**
     * 商场配置查看
     * @return java.util.Map<java.lang.String,java.lang.String>
     * @author qj
     * @since 2022/10/12 19:03
     */
    @Override
    public Map<String, String> querySystemConfigNameAndValue() {
        MarketSystemExample marketSystemExample = new MarketSystemExample();
        MarketSystemExample.Criteria criteria = marketSystemExample.createCriteria();
        List<String> values = new ArrayList<>();
        values.add("market_mall_longitude");
        values.add("market_mall_latitude");
        values.add("market_mall_address");
        values.add("market_mall_qq");
        values.add("market_mall_phone");
        values.add("market_mall_name");
        criteria.andKeyNameIn(values);
        marketSystemExample.or(criteria);
        List<MarketSystem> marketSystems = marketSystemMapper.selectByExample(marketSystemExample);
        Map<String, String> map = new HashMap<>();
        int s = marketSystems.size();
        MarketSystem[] marketSystem = new MarketSystem[s];
        MarketSystem[] marketSystems1 = marketSystems.toArray(marketSystem);
        for (int i = 0; i < marketSystems1.length; i++) {
            map.put(marketSystems1[i].getKeyName(), marketSystems1[i].getKeyValue());
        }
        return map;
    }

    /**
     * 商场配置更新
     * @param map
     * @return void
     * @author qj
     * @since 2022/10/12 19:04
     */
    @Override
    public void updateSystemConfigValue(Map map) {
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            MarketSystem marketSystem = new MarketSystem();
            marketSystem.setKeyValue(entry.getValue());
            Date date = new Date();
            marketSystem.setUpdateTime(date);
            MarketSystemExample marketSystemExample = new MarketSystemExample();
            MarketSystemExample.Criteria criteria = marketSystemExample.createCriteria();
            criteria.andKeyNameEqualTo(entry.getKey());
            marketSystemMapper.updateByExampleSelective(marketSystem, marketSystemExample);
        }

    }
    /**
     * 运费配置查看
     * @return java.util.Map<java.lang.String,java.lang.String>
     * @author qj
     * @since 2022/10/12 19:03
     */
    @Override
    public Map<String, String> queryFreightMinAndValue() {
        MarketSystemExample marketSystemExample = new MarketSystemExample();
        MarketSystemExample.Criteria criteria = marketSystemExample.createCriteria();
        List<String> values = new ArrayList<>();
        values.add("market_express_freight_min");
        values.add("market_express_freight_value");
        criteria.andKeyNameIn(values);
        marketSystemExample.or(criteria);
        List<MarketSystem> marketSystems = marketSystemMapper.selectByExample(marketSystemExample);
        Map<String, String> map = new HashMap<>();
        int s = marketSystems.size();
        MarketSystem[] marketSystem = new MarketSystem[s];
        MarketSystem[] marketSystems1 = marketSystems.toArray(marketSystem);
        for (int i = 0; i < marketSystems1.length; i++) {
            map.put(marketSystems1[i].getKeyName(), marketSystems1[i].getKeyValue());
        }
        return map;
    }

    /**
     * 运费配置更新
     * @param map
     * @return void
     * @author qj
     * @since 2022/10/12 19:04
     */
    @Override
    public void updateFreightMinAndValue(Map map) {
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            MarketSystem marketSystem = new MarketSystem();
            marketSystem.setKeyValue(entry.getValue());
            Date date = new Date();
            marketSystem.setUpdateTime(date);
            MarketSystemExample marketSystemExample = new MarketSystemExample();
            MarketSystemExample.Criteria criteria = marketSystemExample.createCriteria();
            criteria.andKeyNameEqualTo(entry.getKey());
            marketSystemMapper.updateByExampleSelective(marketSystem, marketSystemExample);
        }
    }

    /**
     * 订单配置查看
     * @return java.util.Map<java.lang.String,java.lang.String>
     * @author qj
     * @since 2022/10/12 19:04
     */
    @Override
    public Map<String, String> queryOrder() {
        MarketSystemExample marketSystemExample = new MarketSystemExample();
        MarketSystemExample.Criteria criteria = marketSystemExample.createCriteria();
        List<String> values = new ArrayList<>();
        values.add("market_order_unconfirm");
        values.add("market_order_unpaid");
        values.add("market_order_comment");
        criteria.andKeyNameIn(values);
        marketSystemExample.or(criteria);
        List<MarketSystem> marketSystems = marketSystemMapper.selectByExample(marketSystemExample);
        Map<String, String> map = new HashMap<>();
        int s = marketSystems.size();
        MarketSystem[] marketSystem = new MarketSystem[s];
        MarketSystem[] marketSystems1 = marketSystems.toArray(marketSystem);
        for (int i = 0; i < marketSystems1.length; i++) {
            map.put(marketSystems1[i].getKeyName(), marketSystems1[i].getKeyValue());
        }
        return map;
    }
    /**
     * 订单配置更新
     * @param map
     * @return void
     * @author qj
     * @since 2022/10/12 19:04
     */
    @Override
    public void updateOder(Map map) {
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            MarketSystem marketSystem = new MarketSystem();
            marketSystem.setKeyValue(entry.getValue());
            Date date = new Date();
            marketSystem.setUpdateTime(date);
            MarketSystemExample marketSystemExample = new MarketSystemExample();
            MarketSystemExample.Criteria criteria = marketSystemExample.createCriteria();
            criteria.andKeyNameEqualTo(entry.getKey());
            marketSystemMapper.updateByExampleSelective(marketSystem, marketSystemExample);
        }
    }

    /**
     * 小程序配置查看
     * @return java.util.Map<java.lang.String,java.lang.String>
     * @author qj
     * @since 2022/10/12 19:05
     */
    @Override
    public Map<String, String> queryWx() {
        MarketSystemExample marketSystemExample = new MarketSystemExample();
        MarketSystemExample.Criteria criteria = marketSystemExample.createCriteria();
        List<String> values = new ArrayList<>();
        values.add("market_wx_index_new");
        values.add("market_wx_index_topic");
        values.add("market_wx_share");
        values.add("market_wx_index_brand");
        values.add("market_wx_catlog_goods");
        values.add("market_wx_catlog_list");
        values.add("market_wx_index_hot");
        criteria.andKeyNameIn(values);
        marketSystemExample.or(criteria);
        List<MarketSystem> marketSystems = marketSystemMapper.selectByExample(marketSystemExample);
        Map<String, String> map = new HashMap<>();
        int s = marketSystems.size();
        MarketSystem[] marketSystem = new MarketSystem[s];
        MarketSystem[] marketSystems1 = marketSystems.toArray(marketSystem);
        for (int i = 0; i < marketSystems1.length; i++) {
            map.put(marketSystems1[i].getKeyName(), marketSystems1[i].getKeyValue());
        }
        return map;
    }

    /**
     * 小程序配置更新
     * @param map
     * @return void
     * @author qj
     * @since 2022/10/12 19:05
     */
    @Override
    public void updateWx(Map map) {
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            MarketSystem marketSystem = new MarketSystem();
            marketSystem.setKeyValue(entry.getValue());
            Date date = new Date();
            marketSystem.setUpdateTime(date);
            MarketSystemExample marketSystemExample = new MarketSystemExample();
            MarketSystemExample.Criteria criteria = marketSystemExample.createCriteria();
            criteria.andKeyNameEqualTo(entry.getKey());
            marketSystemMapper.updateByExampleSelective(marketSystem, marketSystemExample);
        }
    }

}
